package cn.edu.sdjzu.xg.bysj.service;

import cn.edu.sdjzu.xg.bysj.dao.GraduateProjectCategoryDao;
import cn.edu.sdjzu.xg.bysj.domain.GraduateProjectCategory;
import util.JdbcHelper;
import util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public final class GraduateProjectCategoryService {
	private GraduateProjectCategoryDao graduateProjectCategoryDao =
			GraduateProjectCategoryDao.getInstance();
	//本类的一个对象引用，保存自身对象
	private static GraduateProjectCategoryService graduateProjectCategoryService =
			new GraduateProjectCategoryService();

	//私有的构造方法，防止其它类创建它的对象
	private GraduateProjectCategoryService(){}
	//静态方法，返回本类的惟一对象
	public synchronized static GraduateProjectCategoryService getInstance() {
		return graduateProjectCategoryService;
	}

	public Collection<GraduateProjectCategory> findAll(Pagination pagination,
													   List conditions_json)
			throws SQLException {
		Connection conn = JdbcHelper.getConn();
		Collection<GraduateProjectCategory> graduateProjectCategories = null;
		graduateProjectCategories = graduateProjectCategoryDao.findAll(conn,pagination,conditions_json);
		JdbcHelper.close(conn);
		return graduateProjectCategories;
	}

	public GraduateProjectCategory find(Integer id) throws SQLException{
		Connection conn = JdbcHelper.getConn();
		GraduateProjectCategory graduateProjectCategory = null;
		graduateProjectCategory = graduateProjectCategoryDao.find(id,conn);
		JdbcHelper.close(conn);
		return graduateProjectCategory;
	}

	public boolean update(GraduateProjectCategory graduateProjectCategory) throws SQLException{
		Connection conn = JdbcHelper.getConn();
		boolean updated = false;
		updated = graduateProjectCategoryDao.update(graduateProjectCategory,conn);
		JdbcHelper.close(conn);
		return updated;
	}

	public boolean add(GraduateProjectCategory graduateProjectCategory) throws SQLException{
		Connection conn = JdbcHelper.getConn();
		boolean added = false;
		added = graduateProjectCategoryDao.add(graduateProjectCategory,conn);
		JdbcHelper.close(conn);
		return added;
	}
	public boolean delete(GraduateProjectCategory graduateProjectCategory) throws SQLException{
		Connection conn = JdbcHelper.getConn();
		boolean deleted = false;
		deleted = graduateProjectCategoryDao.delete(graduateProjectCategory,conn);
		JdbcHelper.close(conn);
		return deleted;
	}

//	public boolean delete(Integer id) throws SQLException{
//		Connection conn = JdbcHelper.getConn();
//		boolean deleted = false;
//		deleted = graduateProjectCategoryDao.delete(id,conn);
//		JdbcHelper.close(conn);
//		return deleted;
//	}


}
